package org.windblog.core;

public class GeneralTemplate {
	
	
	public static String getThemeRoot()
	{
		return OptionService.getOptionValue("theme_root");
	}
	

	public static String currentTheme()
	{
		return OptionService.getOptionValue("template");
	}
	
	private static Boolean isExist(String path)
	{
		java.io.File theFile = new java.io.File(path);
		return theFile.exists();
	}
	
	public static String getThemePath()
	{
		return getThemeRoot()+currentTheme();
	}
	
	public static String getHeader()
	{
		return getThemePath()+"/header.jsp";
	}
	
	public static String getHeader(String name)
	{
		String path = getThemePath()+"/header-"+name+".jsp";
		if(isExist(WBQuery.getServletContext().getRealPath(path)))
			return path;
		else
			return getHeader();
	}
	
	public static String getIndex()
	{
		return getThemePath()+"/index.jsp";
	}
	
	public static String getSingle()
	{
		return getThemePath()+"/single.jsp";
	}
	
	public static String getArchive()
	{
		return getThemePath()+"/archive.jsp";
	}
	
	public static String getPage()
	{
		return getThemePath()+"/page.jsp";
	}

	public static String getFooter() 
	{
		return getThemePath()+"/footer.jsp";
	}
	
	public static String getFooter(String name) 
	{
		String path = getThemePath()+"/footer-"+name+".jsp";
		if(isExist(WBQuery.getServletContext().getRealPath(path)))
			return path;
		else
			return getFooter();
	}
	
	public static String getSidebar() 
	{
		return getThemePath()+"/sidebar.jsp";
	}
	
	public static String getSidebar(String name) 
	{
		String path = getThemePath()+"/sidebar-"+name+".jsp";
		if(isExist(WBQuery.getServletContext().getRealPath(path)))
			return path;
		else
			return getSidebar();
	}

	public static String getCommentTemplate() {
		return getThemePath()+"/comments.jsp";
	}

	public static String getCommentTemplate(String param) {
		String path = getThemePath()+param;
		if(isExist(WBQuery.getServletContext().getRealPath(path)))
			return path;
		else
			return getCommentTemplate();
	}
	
}